package com.example.demo810.exception;

/**
 * @author lzh
 * @date 2020/8/10 - 14:58
 */

import com.example.demo810.vo.AjaxResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Rest控制器异常处理类
 */
@RestControllerAdvice(annotations = RestController.class) // 全局异常处理
public class RestGlobalExceptionHandler {
    /**
     * 处理BaseException类(及其子类)的异常
     */
    @ExceptionHandler({ BaseException.class })
    public AjaxResponse baseExceptionHandler(BaseException e) {
        return new AjaxResponse(e);
    }

    /**
     * 处理Exception类的异常
     */
    @ExceptionHandler({ Exception.class })
    public AjaxResponse exceptionHandler(Exception e) {
        return new AjaxResponse(e);
    }


}
